import { defineStore } from 'pinia';


export const useStore = defineStore('cpsp', {
  state: () => {
    return {
      "city": "",
      "weather": {},
      "village": null,//当前小区
      "mode": null,//当前场景
      "modeCN": null,//当前场景中文名
      "cameraInfo": null,//当前的相机信息
      "showSidebar": false,//显示侧边栏
      "population": {},//人口
      "showToolbar": false,//显示工具栏
    }
  },
  actions: {
    setCity(city) {
      this.city = city;
    },
    setWeater(weather) {
      this.weather = weather;
    },
    setVillage(village) {
      this.village = village;
    },
    setMode(mode) {
      this.mode = mode;
    },
    setModeCN(modeCN) {
      this.modeCN = modeCN;
    },
    setCameraInfo(cameraInfo) {
      this.cameraInfo = cameraInfo;
    },
    setShowSidebar(status) {
      this.showSidebar = status;
    },
    setPopulation(population) {
      this.population = population;
    },
    setShowToolbar(status) {
      this.showToolbar = status;
    }
  },
  //数据持久化插件,避免刷新页面后数据丢失  
  //安装插件:  npm install pinia-plugin-persist
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'cpsp',  //自定义 Key值
        storage: localStorage,  // 选择存储方式
      },
    ],
  }
})
